package com.gzcstec.result;

/**
 * 返回数据统一封装类
 */
public class Result<T> {

    /**
     * 状态码
     */
    private int code;

    /**
     * 返回信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    private Result(T data) {
        this.code = MsgCode.SUCCESS.getCode();
        this.msg = MsgCode.SUCCESS.getMsg();
        this.data = data;
    }

    private Result(MsgCode mc) {
        this.code = mc.getCode();
        this.msg = mc.getMsg();
    }

    public static <T>Result<T> success(T data) {
        return new Result(data);
    }

    public static <T>Result<T> error(MsgCode mc) {
        return new Result(mc);
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
